package com.srxz.mobilepharmacy.repository;

import com.srxz.mobilepharmacy.entity.ClinicRec;
import com.srxz.mobilepharmacy.entity.ClinicRecView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;

@Repository
public interface ClinicRecViewRepository  extends JpaRepository<ClinicRecView, Integer> {
    @Query("select payer,aid,patid,sn,dt,sex,years " +
            "from ClinicRecView where aid=?1 and mrn=?4 and payer like ?3 and dt>=?2 and  (smed is null or smed='') " +
            "and mid > 999999 " +
            "group by payer,aid,patid,sn,dt,sex,years order by dt,sn desc")
    Object[] findallrecAfter(BigInteger aid, Date startTime, String search, Integer mrn);

    @Query("select payer,aid,patid,sn,dt,sex,years " +
            "from ClinicRecView where aid=?1 and mrn=?4 and  payer like ?3 and dt<?2 and  (smed is null or smed='') " +
            "and mid > 999999 " +
            "group by payer,aid,patid,sn,dt,sex,years order by dt,sn desc")
    Object[] findallrecBefore(BigInteger aid, Date startTime, String search, Integer mrn);

}
